package com.example.demo0

import com.example.util.p

data class Bird(var weight:Double,var age:Int,var color:String){

}

class Student

fun getStu()=Student()

class Kot{
    var stu:Student? = getStu()
    fun dealStu(){
        if(stu != null){
            p(stu)
        }
    }
}

object Mapper{

}

class View{

}


fun View.setOnClickListener(listener:(View?)->Unit){
    listener(null)

}

val sum:Int.(Int)->Int={other->plus(other)}

fun Int.sum(b:Int) = this+b

class HTML{
    fun body(){
        p(this)
    }
}

fun html(init:HTML.()->Unit):HTML{
    val html = HTML()
    html.init()
    return html
}

inline fun <T,R> with2(receiver:T,block:T.()->R):R{
    return receiver.block()
}

inline fun <T> T.apply2(apply:T.()->Unit):T{
    this.apply()
    return this
}

inline fun <T,R> Iterable<T>.map2(transform:(T)->R):List<R>{
    for(i in this)
        transform(i)
    return listOf()
}

inline fun <T> Iterable<T>.filter(predicate: (T)->Boolean):List<T>{
    for(i in this) {
        if (predicate(i)) {
            listOf<T>()
        }
    }
    return listOf<T>()
}

inline fun <T,R> Iterable<T>.fold(initial:R,operation:(acc:R,T)->R):R{
    var accumulator = initial
    for(element in this)
        accumulator = operation(accumulator,element)

    return accumulator
}


inline fun <S,T:S> Iterable<T>.reduce2(operation:(acc:S,T)->S):S{
    val t = this.iterator().next();
    for(i in this){
        operation(t,i)
    }
    return t
}





fun main(){

    println("hello")

    val b = Bird(1.1,3,"red")
    p(b)
    p(b.component3())
    val a = b.copy(weight = 2.2)
    p(a)

    val k = Kot()
    k.dealStu()


    p(sum(1,2))
    p(2.sum(5))


    html{
        body()
    }




}







